<template>
  <div id="sidebar">
    <el-menu
      default-active="/System/StudentsList"
      class="el-menu-vertical-demo"
      :router="true"
    >
      <el-submenu
        v-for="item in sideBarList.list"
        :index="item.index"
        :key="item.index"
      >
        <template slot="title">
          <i :class="item.icon"></i>
          <span>{{ item.title }}</span>
        </template>
        <el-menu-item
          v-for="sub in item.subMenu"
          :index="sub.index"
          :key="sub.index"
          >{{ sub.title }}</el-menu-item
        >
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isAdmin: true,
    };
  },
  created() {
    // 动态菜单基于此代码实现--start
    const isAdmin = JSON.parse(localStorage.getItem("loginUser"));
    this.isAdmin = isAdmin.isAdmins;
    // 动态菜单基于此代码实现--end
  },
  computed: {
    sideBarList() {
      if (this.isAdmin) {
        return {
          list: [
            {
              title: "管理员管理",
              index: "1",
              icon: "el-icon-user",
              subMenu: [
                {
                  title: "查看管理员",
                  index: "/System/AdminList",
                },
                {
                  title: "新增管理员",
                  index: "/System/AdminAdd",
                },
              ],
            },
            {
              title: "销售员管理",
              index: "2",
              icon: "el-icon-school",
              subMenu: [
                {
                  title: "查看销售员",
                  index: "/System/SalesmansList",
                },
              ],
            },
            {
              title: "保险分类管理",
              index: "3",
              icon: "el-icon-s-custom",
              subMenu: [
                {
                  title: "查看保险分类",
                  index: "/System/TypesList",
                },
              ],
            },
            {
              title: "保险产品管理",
              index: "4",
              icon: "el-icon-s-custom",
              subMenu: [
                {
                  title: "查看保险产品",
                  index: "/System/InsuresList",
                },
              ],
            },
            {
              title: "保险订单管理",
              index: "5",
              icon: "el-icon-s-custom",
              subMenu: [
                {
                  title: "查看订单信息",
                  index: "/System/OrdersList",
                },
              ],
            },
            {
              title: "退保申请管理",
              index: "6",
              icon: "el-icon-s-custom",
              subMenu: [
                {
                  title: "处理退保申请",
                  index: "/System/Process",
                },
              ],
            },
            {
              title: "客户管理",
              index: "7",
              icon: "el-icon-s-custom",
              subMenu: [
                {
                  title: "查看客户",
                  index: "/System/CustomerList",
                },
                {
                  title: "处理理赔申请",
                  index: "/System/ClaimsList",
                },
              ],
            },
          ],
        };
      } else {
        return {
          list: [
            {
              title: "保险订单管理",
              index: "1",
              icon: "el-icon-user",
              subMenu: [
                {
                  title: "保险订单列表",
                  index: "/System/InsuresOrdersList",
                },
              ],
            },
            {
              title: "客户管理",
              index: "2",
              icon: "el-icon-school",
              subMenu: [
                {
                  title: "我的客户",
                  index: "/System/MyCustomerList",
                },
              ],
            },
            {
              title: "理赔管理",
              index: "3",
              icon: "el-icon-s-custom",
              subMenu: [
                {
                  title: "理赔列表",
                  index: "/System/MyClaimsList",
                },
                {
                  title: "新增理赔",
                  index: "/System/SubmitClaimMsg",
                },
              ],
            },
          ],
        };
      }
    },
  },
};
</script>

<style>
</style>